﻿<?php


      if(!empty($_POST)){
          //多张图片上传
          if(!empty($_FILES['url']['name'][0])){
              $filelist = array();
          }

          foreach ($_FILES['url']['name'] as $key => $v){
              $filelist[$key]['name'] = $v;
              $filelist[$key]['type'] = $_FILES['url']['type'][$key];
              $filelist[$key]['tmp_name'] = $_FILES['url']['tmp_name'][$key];
              $filelist[$key]['error'] = $_FILES['url']['error'][$key];
              $filelist[$key]['size'] = $_FILES['url']['size'][$key];

              }

          foreach ($filelist as $ke => $vv) {
                  $uploaded = uploaded($vv);
          }
           $url=$uploaded;//上传图片
    	     $title = $_POST['title'];//标题
           $type =$_POST['type'];//类型
        	 $author = $_POST['author'];//作者
           $content = $_POST['content'];//内容
           $publisher = $_POST['publisher'];//内容
           //把要上次的数据存储在 $where的数组里面
           $where['url']=$url;
           $where['title']=$title;
           $where['author']=$author;
           $where['type']=$type;
           $where['content']=$content;
           $where['publisher']=$publisher;
           $rows=db_add('news',$where);
          // $sql = "insert into `news` (`title`,`type`,`url`,`author`,`content`) values('$title','$type','$uploaded','$author','$content')";
				  // mysqli_query($link,$sql);
				  // $rows = mysqli_affected_rows($link);
				  if ($rows>0) {
      			echo '<script>alert("添加成功");location.href="index.php?c=news&a=list&admin=1"</script>';die;
      		}else{
      				echo '<script>alert("添加失败");history.go(-1);</script>';die;
      		 }


		}
    ob_clean();
    $id=empty($_GET['id'])?0:$_GET['id'];
    $sql = "select * from `cate` where `pid`=$id";
    $result =mysqli_query($link,$sql);
    $data = array();//最终存储新闻表的所有数据数组
    while ($row = mysqli_fetch_assoc($result)) {
      $data[]=$row;
    }
    if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) {
        echo json_encode($data); die;
    }

      //视图加载页面
      include (VIEW_LAYER.'/admin/layout.html');
?>